package com.how.warlock.engine;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageLoader {
	public static BufferedImage loadImage(String ref) throws IOException{
		BufferedImage bufferedImage = ImageIO.read(new File(ref));
		return bufferedImage;
	}
	

	
	public static BufferedImage[] loadImage(String ref, int width, int height) throws IOException{
		BufferedImage bufferedImage = ImageIO.read(new File(ref));
		
		int imageWidth = bufferedImage.getWidth();
		int imageHeight = bufferedImage.getHeight();
		
		
		int x = imageWidth/width;
		int y = imageHeight/height;
		int amount = x * y;
		
		BufferedImage images[] = new BufferedImage[amount];
		
		
		for (int j = 0; j < y; j++){
			for(int i = 0; i < x; i++){
				BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
				Graphics g = image.getGraphics();
				
				g.drawImage(bufferedImage, 0, 0, width, height,i*width, j*height, (i+1)*width, (j+1) * height, null);
				g.dispose();
				images[j*x + i] =  image;
			}
		}
		
		return images;
	}
}
